package com.snake.springboot.custom.service.impl.base;

import com.snake.springboot.custom.api.model.base.CustRoleAccModel;
import com.snake.springboot.custom.api.response.base.CustRoleAccRsp;
import com.snake.springboot.custom.api.service.base.CustRoleAccService;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustRoleAccDO;
import com.snake.springboot.custom.dao.mybatis.mappers.base.CustRoleAccMapper;
import com.snake.springboot.custom.service.assemble.base.CustRoleAccAssemble;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户角色和账户关系实现类Service
 * 类{@code CustRoleAccServiceImpl} </br>
 * 创建时间 2025/02/08 09:36
 * @author yangxt
 * @see
 */
@Service
public class CustRoleAccServiceImpl implements CustRoleAccService {

    @Autowired
    private CustRoleAccMapper custRoleAccMapper;

    @Override
    public void authorization(List<CustRoleAccModel> model) {
        if(ListUtils.isEmpty(model)){
            return;
        }
        List<CustRoleAccDO> dos = ListUtils.copy(model, CustRoleAccDO.class);
        custRoleAccMapper.delByAccountId(model.get(0).getSubAccountId());
        custRoleAccMapper.batchInsert(dos);
    }

    @Override
    public void cancelAuthorization(String accountId) {
        custRoleAccMapper.delByAccountId(accountId);
    }

    @Override
    public List<CustRoleAccRsp> queryList(CustRoleAccModel params) {
        CustRoleAccDO queryDO = CustRoleAccAssemble.roleAccDOAss(params);
        List<CustRoleAccDO> accDOList = custRoleAccMapper.queryList(queryDO);
        List<CustRoleAccRsp> rspList = ListUtils.copy(accDOList, CustRoleAccRsp.class);
        return rspList;
    }
}
